import Vue from 'vue'
import Vuex from 'vuex'
import miaosha from "./miaosha" // eslint-disable-line no-unused-vars
import axios from 'axios'
// w无法调用Vue ，只能自定义一下axios
Vue.use(Vuex)
import qs from 'qs'

const actions = {
    // 注意有一个默认参数
    miaoshaReduceOne(context, id) {
        
        console.log(this.state.MYURL + `/miaosha/reduceOne/${Vue.$cookies.get("userId")}/${id}`)

        // qid  aid(id =>>  666)
        axios.get(this.state.MYURL + `/miaosha/reduceOne/${Vue.$cookies.get("userId")}/${id}`)
            // http://localhost:8001/miaosha/selectAll 
            .then(res => {
                // console.log("AnswererCount", this.AnswererCount[this.AnswererDatas[0]["id"]])
                // console.log("AnswererDatas.id:",this.AnswererDatas[0])
                // console.log("reduceone  result:",res.data)
                return id + "@@" + res.data
            }
            )
            .catch(function (error) { alert("请求失败" + error) })
    },
    gethead(context,head){
        
        let data = {
            head:head
        }
        axios.post(this.state.MYURL + `/answerer/getHead`,qs.stringify(data))
            // http://localhost:8001/miaosha/selectAll 
            .then(res => {
                // console.log("AnswererCount", this.AnswererCount[this.AnswererDatas[0]["id"]])
                // console.log("AnswererDatas.id:",this.AnswererDatas[0])
                // console.log("reduceone  result:",res.data)
                return res
            }
            )
            .catch(function (error) { alert("请求失败" + error) })
    },
    
  
}

const mutations = {
    test0() {
        alert("store test0 .commit===> mutations")
    },


}

const getters={
    isAnswerer(){
        if(Vue.$cookies.get("authority")=="Answerer" || Vue.$cookies.get("authority")=="Root" ){
            return true;
        }
        return false
    }
}


const state = {
    id: "fafafafafaf",
    fafa: "sasa",
    MYURL:"http://47.107.93.49:8001",
    userData: {
        // "username": "admin",
        // id: localStorage.getItem("id"),
        // authority:localStorage.getItem("authority"),  
    }
}

export default new Vuex.Store({// eslint-disable-line no-unused-vars
    modules: {
        miaosha,
    },
    actions,
    state,
    mutations,
    getters
})